class Solution {
    public static void main(String[] args) {
        int[] arr = {-3,-2,-3} ;
        System.out.println(class Solution {
            public int maxSubarraySumCircular(int[] nums) {
                int len = nums.length ;
                int[] f = new int[len] ;
                int[] g = new int[len] ;
                int sum = 0 ;
                f[0] = nums[0] ;
                g[0] = nums[0] ;
                int max = nums[0]  , min = nums[0];
                sum += nums[0] ;
                for(int i=1 ; i < len ; i ++){
                    f[i] = Math.max(nums[i] , f[i-1]+nums[i]);
                    g[i] = Math.min(nums[i] , g[i-1]+nums[i]) ;
                    max = Math.max(max , f[i]);
                    min = Math.min(min , g[i]) ;
                    sum+=nums[i] ;
                }
                if(sum-min==0){
                    return max ;
                }
                return Math.max(max ,sum- min) ;
            }
        }maxSubarraySumCircular(arr));
    }
    public static int maxSubarraySumCircular(int[] nums) {
        int len = nums.length ;
        int[] f = new int[len] ; 
        int[] g = new int[len] ;
        int sum = 0 ; 
        f[0] = nums[0] ; 
        g[0] = nums[0] ; 
        int max = -Integer.MAX_VALUE  , min = Integer.MAX_VALUE;
        sum += nums[0] ; 
        for(int i=1 ; i < len ; i ++){
            f[i] = Math.max(nums[i] , f[i-1]+nums[i]);
            g[i] = Math.min(nums[i] , g[i-1]+nums[i]) ; 
            max = Math.max(max , f[i]);
            min = Math.min(min , g[i]) ; 
            sum+=nums[i] ; 
        }
        return Math.max(max , sum-min) ; 
    }
}